<!--
用法
<ueditor ref="editor" style="width: 100%;" @change="change" @ready="ready"></ueditor>
-->
<template>
  <div>
    <div ref="editor" style="z-index:0;">
    </div>
  </div>
</template>
<script>
  import '../../../static/ueditor/ueditor.config';
  import '../../../static/ueditor/ueditor.all.min';
  import '../../../static/ueditor/lang/zh-cn/zh-cn';
  import '../../../static/ueditor/kityformula-plugin/addKityFormulaDialog';
  import '../../../static/ueditor/kityformula-plugin/defaultFilterFix';
  import '../../../static/ueditor/kityformula-plugin/getKfContent';
  export default{
    data(){
      return {
        content: {}
      }
    },
    props: {
      config: {
        type: Object,
        default: function () {
          return {
            //这里可以选择自己需要的工具按钮名称,此处仅选择如下五个
            toolbars: [['Source', 'Undo', 'Redo', 'Bold', 'forecolor', 'indent', 'test', 'cleardoc', 'paragraph', 'inserttable', 'link', 'unlink', 'lineheight','kityformula', 'simpleupload', 'fullscreen']],
            //
            autoHeightEnabled: false,
            initialFrameHeight:300,
            //focus时自动清空初始化时的内容
            autoClearinitialContent: true,
            //tel
            allowLinkProtocols: ['tel:'],
            //关闭字数统计
            wordCount: false,
            //关闭elementPath
            elementPathEnabled: false,
            imageUrlPrefix:'http://demo.loyin.net:8080'
          }
        }
      }
    },
    methods: {
      setContent(value) {
        if (this.editor && value) {
          this.editor.setContent(value)
        }
      }
    },
    beforeDestroy() {
      this.editor.destroy()
    },
    mounted() {
      this.$nextTick(function f1() {
        // 保证 this.$el 已经插入文档
        var vm = this;
        var editor_id = 'ueditorId' + Math.random(10);
        this.$refs.editor.id = editor_id
        require.ensure([], require => {
          this.editor = UE.getEditor(editor_id, this.config)
          this.editor.ready(() => {
            this.editor.addListener("contentChange", () => {
              const content = this.editor.getContent()
              this.$emit('change', content)
            })
            this.$emit('ready', this.editor)
          })
        })
      });
    },
    created() {
      const self = this;
    },
    computed: {},
    components: {}
  }
</script>
<style>

</style>
